<template>
  <div class="app-container">
    <eHeader :param-bean="paramBean" :sup_this="sup_this" />
    <eForm ref="form" :sup_this="sup_this" />
    <XlsImportForm ref="XlsImportForm" :import-url="importUrl" :import-template-url="importTemplateUrl" :sup_this="sup_this" />
    <PrintPageForm ref="PrintPageForm" :sup_this="sup_this" :print-url="printUrl" report-code="cpy_report_code" />
    <XlsExportForm ref="XlsExportForm" :sup_this="sup_this" :export-url="exportUrl" report-code="cpy_report_code" />
    <!--表格渲染-->
    <DataGridTable
      v-loading="loading"
      ref="mainTable"
      :sup_this="sup_this"
      :data="data.rtnList"
      :total="total"
      :all-define-columns="['cpyName','cpyLongName','cerCode','cpyType','cpyStatus','enableFlag','lastUpdateDate']"
      grid-id="cpyMngMainGridId"
      @selection-change="handleGridSelectionChange">
      <!--<el-table-column slot="cpyCode" slot-scope="columnscope" :label="columnscope.data&&columnscope.data.label ? columnscope.data.label : '公司编号'" :width="columnscope.data&&columnscope.data.width ? columnscope.data.width : '150px'" prop="cpyCode">-->
      <DataGridColumnSlot prop="cpyCode" label="公司编号" sortable="custom" width="180px" >
        <template slot-scope="scope">
          <edit :data="scope.row" :sup_this="sup_this" />
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="cpyName" prop="cpyName" label="简称" width="100px" />
      <DataGridColumn slot="cpyLongName" prop="cpyLongName" label="全称" width="150px" />
      <DataGridColumn slot="cerCode" prop="cerCode" label="证件编号" width="200px" />
      <DataGridColumnSlot slot="cpyType" prop="cpyType" label="公司类型" align="center">
        <template slot-scope="scope">
          <div v-for="item in dicts.cpy_type" :key="item.id">
            <span v-if="scope.row.cpyType.toString() === item.dictCode" :type="''">{{ item.dictName }}</span>
          </div>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="cpyStatus" prop="cpyStatus" label="状态" align="center">
        <template slot-scope="scope">
          <div v-for="item in dicts.cpy_status" :key="item.id">
            <el-tag v-if="scope.row.cpyStatus.toString() === item.dictCode" :type="scope.row.cpyStatus === 'ONLINE' ? '' : 'info'">{{ item.dictName }}</el-tag>
          </div>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="enableFlag" prop="enableFlag" label="是否有效" align="center">
        <template slot-scope="scope">
          <div v-for="item in dicts.enable_flag" :key="item.id">
            <el-tag v-if="scope.row.enableFlag.toString() === item.dictCode" :type="scope.row.enableFlag === 'Y' ? '' : 'info'">{{ item.dictName }}</el-tag>
          </div>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="lastUpdateDate" prop="lastUpdateDate" label="更新日期" width="200px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdateDate) }}</span>
        </template>
      </DataGridColumnSlot>
    </DataGridTable>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import { parseTime } from '@/utils/index'
import initData from '@/mixins/initData'
import eHeader from './module/header'
import eForm from './module/form'
import edit from './module/edit'
import { del, loadDataUrl, exportUrl, importUrl, importTemplateUrl, printUrl } from '@/api/system/cpy'
import XlsImportForm from '@/views/components/XlsImportForm'
import PrintPageForm from '@/views/components/PrintPageForm'
import XlsExportForm from '@/views/components/XlsExportForm'

export default {
  components: { XlsExportForm, PrintPageForm, XlsImportForm, eHeader, eForm, edit },
  mixins: [initData],
  // 设置数据字典
  dictTypes: ['cpy_status', 'enable_flag', 'cpy_type'],
  data() {
    return {
      delLoading: false,
      sup_this: this,
      importUrl: importUrl(),
      exportUrl: exportUrl(),
      importTemplateUrl: importTemplateUrl(),
      printUrl: printUrl()
    }
  },
  created() {
    this.url = loadDataUrl()
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    async beforeInit() {
      return true
    },
    subDelete(id) {
      this.delLoading = true
      const data = { idList: [id] }
      del(data).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err)
      })
    }
  }
}
</script>
